import java.util.Stack;

public class T {
}

class Solution {
    public boolean isValid(String s) {

        Stack<Character> stack=new Stack<>();
        char cc;
        for (int i = 0; i < s.length(); i++) {
            char c=s.charAt(i);

            switch (c){
                case '[':
                   stack.push(c);
                    break;
                case '(':
                    stack.push(c);
                    break;
                case  '{':
                    stack.push(c);
                    break;

                case  ']':
                    if(stack.empty()){
                        return false;
                    }
                     cc=stack.pop();
                    if(cc!='['){
                        return false;
                    }
                    break;
                case  '}':
                    if(stack.empty()){
                        return false;
                    }
                     cc=stack.pop();
                    if(cc!='{'){
                        return false;
                    }
                    break;
                case  ')':
                    if(stack.empty()){
                        return false;
                    }
                    cc=stack.pop();
                    if(cc!='('){
                        return false;
                    }
                    break;
                default:
                    break;
            }
        }

        if(stack.empty()){
            return true;

        }else  {
            return false;
        }


    }
}
